package com.kaijie.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kaijie.entity.RoomInfnEntity;
import com.kaijie.entity.RoomSortInfnEntity;
import com.kaijie.service.RoomInfnService;
import com.kaijie.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kaijie.entity.RoomReserveEntity;
import com.kaijie.service.RoomReserveService;
import com.kaijie.utils.PageUtils;
import com.kaijie.utils.R;



/**
 * 
 *
 * @author Jy
 * @email 846021119@qq.com
 * @date 2022-02-28 12:02:21
 */
@RestController
@RequestMapping("kaijie/roomreserve")
public class RoomReserveController {
    @Autowired
    private RoomReserveService roomReserveService;
    @Autowired
    RoomInfnService roomInfnService;

    @RequestMapping("/selRmId/{rmid}")
    //@RequiresPermissions("kaijie:movecheck:info")
    public R selRmId(@PathVariable("rmid") Integer rmid){
//        Map m=new HashMap();
//        m.put("rmid",rmid);
//        m.put("reserve","reserve");
//        m.put("useState","useState");
        RoomInfnEntity roomReserve = roomInfnService.getOne(new QueryWrapper<RoomInfnEntity>().eq("rmid", rmid));
        //roomInfnEntity.setRemarks("");
       //List<RoomInfnEntity> roomInfn=roomInfnService.listByMap(m);
        return R.ok().put("roomReserve", roomReserve);
    }

    @RequestMapping("/listID")
    //@RequiresPermissions("kaijie:roomsortinfn:list")
    public Map<String, Object> listID(@RequestParam Map<String, Object> params){
        List<RoomInfnEntity> roomInfnEntityList=roomInfnService.list();
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        map.put("count",roomInfnEntityList.size());
        map.put("msg"," ");
        map.put("data",roomInfnEntityList);
        return map;
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("kaijie:roomreserve:list")
    public Map<String, Object> list(@RequestParam Map<String, Object> params){
        List<RoomReserveEntity> r=roomReserveService.list();
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        map.put("count",r.size());
        map.put("msg"," ");
        map.put("data",r);
        return map;

    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("kaijie:roomreserve:info")
    public R info(@PathVariable("id") Integer id){
        RoomReserveEntity roomReserve = roomReserveService.getById(id);

        return R.ok().put("roomReserve", roomReserve);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("kaijie:roomreserve:save")
    public R save(@RequestBody RoomReserveEntity roomReserve){
        roomReserveService.save(roomReserve);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("kaijie:roomreserve:update")
    public R update(@RequestBody RoomReserveEntity roomReserve){
        ValidatorUtils.validateEntity(roomReserve);
        roomReserveService.updateById(roomReserve);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("kaijie:roomreserve:delete")
    public R delete(@RequestBody Integer[] ids){
        roomReserveService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
